<template>
    <div>
        <el-button style="background-color: rgb(26,179,148);color: #fff" @click="exportExcel">导出</el-button>
    </div>
</template>

<script>
    export default {
        name: "balance",
        data() {
            return {

            }
        },
        methods: {
            // 导出按钮事件
            exportExcel(index, row) {
                const apiUrl = "/admin/finance/balanceList"
                let param = new URLSearchParams();
                param.append("length", 10000);
                param.append("export", 1);
                this.$axios.post(apiUrl, param,{responseType: 'blob'}).then((res) => {
                    console.log( res.data)
                    const link = document.createElement('a')
                    let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'});
                    link.style.display = 'none'
                    link.href = URL.createObjectURL(blob);
                    let num = ''
                    for(let i=0;i < 10;i++){
                        num += Math.ceil(Math.random() * 10)
                    }
                    link.setAttribute('download', '系统现存余额表' + num + '.xlsx')
                    document.body.appendChild(link)
                    link.click()
                    document.body.removeChild(link)
                })
            },
        }
    }
</script>

<style scoped>

</style>
